package com.lutus.android.biz.mall

/**
 * author : chong.huang
 * create : 2021/12/9
 * desc   :
 */


/**
 * author  : chong.huang
 * time    : 2021/12/10 10:45
 * desc    : 取区间值, 超出这个范围就会取 min or max
 */
fun Float.interval(min: Float, max: Float): Float {
    return if (this < min) min else if (this > max) max else this
}

fun Float.progress(min: Float, max: Float): Float {
    return if (this < min) 0F else if (this > max) 1F else (this - min) / (max - min)
}

fun Int.interval(min: Int, max: Int): Int {
    return if (this < min) min else if (this > max) max else this
}

fun Int.interval(range: IntRange): Int {
    return interval(range.first, range.last)
}

/**
 * author  : chong.huang
 * time    : 2021/12/10 10:45
 * desc    : 计算区间范围的进度
 */
fun IntRange.progress(progress: Float): Int = ((endInclusive - start) * progress).toInt() + start